package org.demo.nio;

import org.demo.client.Client;
import org.demo.nio.reactor.multiplereactor.MainReactor;
import org.demo.nio.reactor.multiplethread.MultipleThreadReactor;
import org.demo.nio.reactor.simple.SimpleReactor;

import java.io.IOException;

/**
 * Created by tangwy on 2017/10/30.
 */
public class NioTest {
    public static void simpleReactorTest() throws IOException, InterruptedException {
        new Thread(new SimpleReactor(30000)).start();
        Thread.sleep(2000);
        new Thread(new Runnable() {
            @Override
            public void run() {
                Client client = new Client();
                client.start();
            }
        }).start();
    }

    public static void multiThreadReactorTest() throws IOException, InterruptedException {
        new Thread(new MultipleThreadReactor(30000)).start();
        Thread.sleep(2000);
        new Thread(new Runnable() {
            @Override
            public void run() {
                Client client = new Client();
                client.start();
            }
        }).start();
    }

    public static void multiReactorTest() throws IOException, InterruptedException {
        new Thread(new MainReactor(30000)).start();
        Thread.sleep(5000);
        for (int i = 0; i < 20; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    Client client = new Client(Thread.currentThread().getName());
                    client.start();
                }
            }).start();

        }
    }
}
